﻿/* 4. Write a program that finds the maximal sequence of equal elements in an array. 
 * Example: {2, 1, 1, 2, 3, 3, 2, 2, 2, 1} -> {2, 2, 2} */

using System;

public class MaximalSequence
{
    public static void Main()
    {
        ulong arrayLength;
        string[] array;
        ulong firstMaxSequence;
        string valueInFirstMaxSequence;
        ulong currentMaxSequence = 0;
        ulong pointer;
        ulong counter;

        Console.Write("\nThe length of array: ");
        arrayLength = ulong.Parse(Console.ReadLine());
        Console.WriteLine();

        if (0 < arrayLength)
        {
            array = new string[arrayLength];

            for (ulong i = 0; i < arrayLength; i++)
            {
                Console.Write("Array[{0}] = ", i);
                array[i] = Console.ReadLine();
            }

            firstMaxSequence = 1;
            valueInFirstMaxSequence = array[0];
            pointer = 0;

            while (pointer < arrayLength - 1)
            {
                currentMaxSequence = 1;

                for (counter = pointer + 1; counter < arrayLength; counter++)
                {
                    if (array[pointer] == array[counter])
                        currentMaxSequence++;
                    else
                        break;
                }

                if (currentMaxSequence > firstMaxSequence)
                {
                    firstMaxSequence = currentMaxSequence;
                    valueInFirstMaxSequence = array[pointer];
                }

                pointer = counter;
            }

            Console.Write("\nThe first maximal sequence in this array is\n {0} ", "{");
            for (ulong i = 0; i < firstMaxSequence - 1; i++)
                Console.Write("{0}, ", valueInFirstMaxSequence);

            Console.WriteLine("{0} {1}\n", valueInFirstMaxSequence, "}");
        }
        else
            Console.WriteLine("The length of array must be natural!\n");
    }
}